#ifndef LIVEINFOVIEW_H
#define LIVEINFOVIEW_H

#include "libs/core/model/modeltype.h"
#include "liverecordertype.h"
#include <QTimer>
#include <QWidget>

QT_BEGIN_NAMESPACE
class QWebEngineProfile;
QT_END_NAMESPACE

class WebPage;
class WebView;

class LiveInfoView : public QWidget
{
    Q_OBJECT
public:
    explicit LiveInfoView(const QString& name, QWidget* parent = nullptr);
    ~LiveInfoView();

    bool captchaShown() const { return captcha_shown_; }
    bool passedCaptcha() const { return passed_captcha_; }
    int platform() const { return platform_; }
    int presenter() const { return presenter_; }
    bool handled() const { return handled_; }
    void getLiveInfo(int presenter, int platform, const QString& presenter_platform_id, int timeout,
                     const LiveHandler& handler);
    void unload();

Q_SIGNALS:
    void captchaStateChanged(bool passed);

private:
    QString setLiveInfo(const QString& args, const QString& success_callback,
                        const QString& failure_callback, const QString& sender_id,
                        QWidget* sender_view);
    QString setCaptcha(const QString& args, const QString& success_callback,
                       const QString& failure_callback, const QString& sender_id,
                       QWidget* sender_view);

    const QString name_;
    QWebEngineProfile* profile_;
    WebPage* page_;
    WebView* web_view_;
    QTimer* timer_;
    bool captcha_shown_ = false;
    bool passed_captcha_ = false;
    int platform_ = 0;
    int presenter_ = 0;
    LiveHandler handler_;
    bool handled_ = true;
};

#endif // LIVEINFOVIEW_H
